import { GlobalValue } from "../utils";

const roleUpgrader = {
    /** @param {Creep} creep **/
    run: function (creep) {
        // console.log("轮到我了：", creep.name)
        if (creep.memory.mainworking && creep.store[RESOURCE_ENERGY] === 0) {
            creep.memory.mainworking = false;
            creep.say("🔄 harvest");
        }
        if (!creep.memory.mainworking && creep.store.getFreeCapacity() === 0) {
            creep.memory.mainworking = true;
            creep.say("🚧 upgrade");
        }
        // console.log(creep.store)
        if (!creep.memory.mainworking) {
            // console.log("去采矿咯")
            // const sources = creep.room.find(FIND_SOURCES)
            const sources = GlobalValue.sources;
            if (creep.harvest(sources[1]) === ERR_NOT_IN_RANGE) {
                creep.moveTo(sources[1], {
                    visualizePathStyle: { stroke: "#ffaa00" }
                });
            }
        } else {
            // console.log("去升级咯")
            if (
                creep.upgradeController(creep.room.controller) ===
                ERR_NOT_IN_RANGE
            ) {
                creep.moveTo(creep.room.controller, {
                    visualizePathStyle: { stroke: "#ffffff" }
                });
            }
        }
    }
};

export { roleUpgrader };
